package com.lanju.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.lanju.entity.SystemAdmin;
import com.lanju.dao.HouseCheckListDao;
import com.lanju.entity.HouseCheckList;
import com.lanju.model.ResultModel;
import com.lanju.service.HouseCheckListService;


@Service
public class HouseCheckListServiceImpl implements HouseCheckListService{

    private static final Logger LOGGER = LoggerFactory.getLogger(HouseCheckListServiceImpl.class);
    
    @Autowired
    HouseCheckListDao entityDao;

    /** 新增 */
    @Override
    @Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
    public ResultModel add(HouseCheckList entity) {
        try {
        	entityDao.persist(entity);
            return ResultModel.success("录入成功", null);
        } catch (Exception e) {
            LOGGER.error("addHouseCheckList fail",e);
        }
        return ResultModel.fail("录入失败", null);
    }

    /** 根据id删除 */
    @Override
    @Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
    public ResultModel del(HouseCheckList entity) {
    	String entityId = entity.getHouseId();
        HouseCheckList obj = entityDao.getById(entityId);
        if(obj==null){
            return ResultModel.fail("HouseCheckList不存在", null);
        }
        try {
            entityDao.remove(entity);;
            return ResultModel.success("删除成功", null);
        } catch (Exception e) {
            LOGGER.error("delHouseCheckList fail",e);
        }
        return ResultModel.fail("删除失败", null);
    }
    
    /** 根据id修改 */
    @Override
    @Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
    public ResultModel edit(HouseCheckList entity) {
        HouseCheckList obj = entityDao.getById(entity.getHouseId());
        if(obj==null){
            return ResultModel.fail("HouseCheckList不存在", null);
        }
        try {
            entityDao.merge(entity);
            return ResultModel.success("编辑成功", null);
        } catch (Exception e) {
            LOGGER.error("editHouseCheckList fail",e);
        }
        return ResultModel.fail("编辑失败", null);
    }

    /** 根据id获取 */
    @Override
    @Transactional(value="financialmarketingTM", readOnly=true)
    public HouseCheckList getById(String id) {
        HouseCheckList obj = entityDao.getById(id);
        return obj;
    }
    
    /** 根据参数获取 */
    @Override
    @Transactional(value="financialmarketingTM", readOnly=true)
    public HouseCheckList getByParam(HouseCheckList entity) {
        HouseCheckList obj = entityDao.getByParam(entity);
        return obj;
    }
    
    

    /** 分页查询 */
    @Override
    @Transactional(value="financialmarketingTM", readOnly=true)
    public Map<String, Object> getList(Map param, int pageSize, int offset) {
    	 Map<String, Object> rsMap = new HashMap<String, Object>();
    	 long count = entityDao.getListCount(param);
         List<HouseCheckList> list = entityDao.getList(param, pageSize, offset);
         rsMap.put("total", count);
         rsMap.put("rows", list);
        return rsMap;
    }
    
    
    @Override
    @Transactional(value="financialmarketingTM", readOnly=true)
    public List<Map> getBaseItemList(Map param) {
        return entityDao.getBaseItemList(param);
    }
    
    @Override
    @Transactional(value="financialmarketingTM", readOnly=true)
    public List<Map> getHouseList(Map param) {
        return entityDao.getHouseList(param);
    }
  
}
